﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.XR;

// Token: 0x02000234 RID: 564
public class VRCamera : MonoBehaviour
{
	// Token: 0x06000BE8 RID: 3048 RVA: 0x00062DF4 File Offset: 0x00060FF4
	private void Start()
	{
		this.VRcamera = GameObject.FindGameObjectWithTag("MainCamera");
		if (this.VRcamera)
		{
			this.farCamera = GameObject.Find("Far Camera");
		}
		this.vrSupported = true;
	}

	// Token: 0x06000BE9 RID: 3049 RVA: 0x00062E30 File Offset: 0x00061030
	private IEnumerator LoadDevice(string newDevice)
	{
		XRSettings.LoadDeviceByName(newDevice);
		yield return null;
		XRSettings.enabled = true;
		yield return null;
		yield break;
	}

	// Token: 0x06000BEA RID: 3050 RVA: 0x00062E4C File Offset: 0x0006104C
	private void EnableMode(bool on, string modeName, VRCamera.Mode mode = VRCamera.Mode.Unknown)
	{
		if (on && (!XRSettings.enabled || this.currentMode != mode))
		{
			this.currentMode = mode;
			base.StartCoroutine(this.LoadDevice(modeName));
		}
		else if (!on && mode == this.currentMode)
		{
			XRSettings.LoadDeviceByName(string.Empty);
		}
	}

	// Token: 0x06000BEB RID: 3051 RVA: 0x00062EAC File Offset: 0x000610AC
	public void ReparentFarCamera(bool value)
	{
		if (this.VRcamera != null && this.farCamera != null)
		{
			if (value)
			{
				this.farCamera.transform.parent = this.VRcamera.transform.parent;
			}
			if (!value)
			{
				this.farCamera.transform.parent = this.VRcamera.transform;
			}
		}
		else
		{
			Debug.LogError("Missing camera refrence!");
		}
	}

	// Token: 0x06000BEC RID: 3052 RVA: 0x00062F34 File Offset: 0x00061134
	public void SelectXR(int sel)
	{
		string text = XRSettings.supportedDevices[sel];
		if (text == "None")
		{
			this.EnableMode(false, "None", this.currentMode);
			Player.vrMode = false;
			this.ReparentFarCamera(false);
		}
		else if (text == "split")
		{
			this.EnableSplit(true);
		}
		else if (text == "stereo")
		{
			this.EnableStereo(true);
		}
		else if (text == "Oculus")
		{
			this.EnableOculus(true);
		}
		else if (text == "OpenVR")
		{
			this.EnableOpenVR(true);
		}
		else
		{
			this.EnableMode(true, text, VRCamera.Mode.Unknown);
			Player.vrMode = true;
			this.ReparentFarCamera(true);
		}
	}

	// Token: 0x06000BED RID: 3053 RVA: 0x00063003 File Offset: 0x00061203
	public void EnableSplit(bool on)
	{
		this.EnableMode(on, "Split", VRCamera.Mode.Split);
		Player.vrMode = on;
		this.ReparentFarCamera(on);
	}

	// Token: 0x06000BEE RID: 3054 RVA: 0x0006301F File Offset: 0x0006121F
	public void EnableStereo(bool on)
	{
		this.EnableMode(on, "Stereo", VRCamera.Mode.Stereo);
	}

	// Token: 0x06000BEF RID: 3055 RVA: 0x0006302E File Offset: 0x0006122E
	public void EnableOculus(bool on)
	{
		this.EnableMode(on, "Oculus", VRCamera.Mode.Oculus);
		Player.vrMode = on;
		this.ReparentFarCamera(on);
	}

	// Token: 0x06000BF0 RID: 3056 RVA: 0x0006304A File Offset: 0x0006124A
	public void EnableOpenVR(bool on)
	{
		this.EnableMode(on, "OpenVR", VRCamera.Mode.OpenVR);
		Player.vrMode = on;
		this.ReparentFarCamera(on);
	}

	// Token: 0x06000BF1 RID: 3057 RVA: 0x00063066 File Offset: 0x00061266
	public bool GetSplit()
	{
		return XRSettings.enabled && this.currentMode == VRCamera.Mode.Split;
	}

	// Token: 0x06000BF2 RID: 3058 RVA: 0x0006307E File Offset: 0x0006127E
	public bool GetStereo()
	{
		return XRSettings.enabled && this.currentMode == VRCamera.Mode.Stereo;
	}

	// Token: 0x06000BF3 RID: 3059 RVA: 0x00063096 File Offset: 0x00061296
	public bool GetOpenVR()
	{
		return XRSettings.enabled && this.currentMode == VRCamera.Mode.OpenVR;
	}

	// Token: 0x06000BF4 RID: 3060 RVA: 0x000630AE File Offset: 0x000612AE
	public bool GetOculus()
	{
		return XRSettings.enabled && this.currentMode == VRCamera.Mode.Oculus;
	}

	// Token: 0x06000BF5 RID: 3061 RVA: 0x000630C6 File Offset: 0x000612C6
	public bool IsInVR()
	{
		return this.currentMode == VRCamera.Mode.OpenVR || this.currentMode == VRCamera.Mode.Oculus;
	}

	// Token: 0x0400113F RID: 4415
	private VRCamera.Mode currentMode;

	// Token: 0x04001140 RID: 4416
	public bool vrSupported;

	// Token: 0x04001141 RID: 4417
	public GameObject VRcamera;

	// Token: 0x04001142 RID: 4418
	public GameObject farCamera;

	// Token: 0x02000235 RID: 565
	private enum Mode
	{
		// Token: 0x04001144 RID: 4420
		None,
		// Token: 0x04001145 RID: 4421
		Split,
		// Token: 0x04001146 RID: 4422
		Stereo,
		// Token: 0x04001147 RID: 4423
		OpenVR,
		// Token: 0x04001148 RID: 4424
		Oculus,
		// Token: 0x04001149 RID: 4425
		Unknown
	}
}
